<%@ page language="java" session="true" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:include page="../common/framework/header.jsp" />
<link href="${pageContext.request.contextPath}/static/plugin/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/static/plugin/daterangepicker/daterangepicker.min.css" rel="stylesheet">
<style type="text/css">
	select.form-control {
	    height: 32px;
	    padding: 4px 6px;
	    width: 140px!important;
	}
	.bs-bars{padding:0;}
</style>
	<div id="container"
		class="effect aside-float aside-bright mainnav-lg navbar-fixed mainnav-fixed aside-fixed">

		<jsp:include page="../common/framework/topper.jsp" />
		<div class="boxed">
			<%--=======================  页面主体内容  ============================--%>
			<div id="content-container">
				<div class="wrappers">
					<%--=========================  页面标题  ==========================--%>
					<div id="page-title">
						<p class="page-header text-overflow table-header">
							日志管理&nbsp;&nbsp;<small>本页面对日志进行管理。详细说明请参考
							<a href="http://confluence.paas.sinopec.com/pages/viewpage.action?pageId=11343322#id-使用手册-_Toc471811850" target="_blank">&lt;使用手册&gt;</a></small>
						</p>
					</div>
					<ol class="breadcrumb">
						<li><a href="#">系统管理</a></li>
						<li class="active">日志管理</li>
					</ol>
					<div id="page-content">
						<div class="panel">
							<div class="panel-body pad-top-no">
								<div id="toolbar">
									<form id="search_form" class="form-inline" autocomplete="off">

										<label class="control-label width-auto" for="appName">用户名称:</label>
										<div class="input-group">
											<input id="execUserName" name="execUserName" type="text" placeholder="请输入" class="form-control" style="width: 120px; margin-right: 0;"/>
										  	<span class="input-group-btn" onclick="searchForm();">
												<a class="btn btn-icon btn-hover-primary" type="button" style="margin-right: 15px;">
													<i class="fa fa-search" ></i>
												</a>
											</span>
										</div>

										<label class="control-label width-auto" for="appName">执行结果:</label>
										<div class="input-group">
											<input id="result" name="result" type="text" placeholder="请输入" class="form-control" style="width: 120px; margin-right: 0;">
										  	<span class="input-group-btn" onclick="searchForm();">
												<a class="btn btn-icon btn-hover-primary" type="button" style="margin-right: 15px;">
													<i class="fa fa-search" ></i>
												</a>
											</span>
										</div>

										<label class="control-label width-auto" for="appGroup">操作类型:</label>
										<select id="operationType" name="operationType" class=" form-control"  onchange="optionChange()">
					                        <option value="">请选择</option>
					                        <option value="0">登录登出</option>
					                        <option value="1">测试套件</option>
					                        <option value="2">测试工具</option>
					                        <option value="3">测试助手</option>
					                        <option value="4">项目管理</option>
					                        <option value="5">测试用例</option>
					                        <option value="6">资源管理</option>
					                        <option value="7">系统管理</option>
					                        <option value="9">其他</option>
					                    </select>

										<label class="control-label width-auto" >执行时间:</label>
										<div class="input-group" style="margin-right: 15px;">
												<input id="daterangepicker" name="date-range-picker"
													   class="form-control text-center" style="width: 245px;margin-right: 0;">
												<div class="input-group-addon">
													<i class="fa fa-calendar"></i>
												</div>
											</div>

										<a id = "reset" class = "btn btn-gray" style="margin-top: 2px;"><i class="glyphicon glyphicon-share-alt"></i>重置</a>
										<a class="btn btn-danger  pull-right" onclick="delLog()" style="margin-top: 2px;">
											<i class="fa fa-trash"></i> 删除
										</a>

									</form>
								</div>
                                  <table id="logRecord" class="table" data-single-select="true" data-toolbar="#toolbar"
               						 data-buttons-class="hover-primary">
                                      <thead>
								        <tr>
								            <th data-field="" data-checkbox="true"></th>
								            <th data-field="execUserName">用户名称</th>
								            <th data-field="content" >执行动作</th>
								            <th data-field="result" >执行结果描述</th>
								            <th data-field="projectName" >操作项目</th>
								            <th data-field="executeTime" data-formatter="invoiceFormatter">执行时间</th>
								        </tr>
								    </thead>
                                  </table>
							</div>
						</div>

			</div>
		</div>
	</div>

		<%--=========================  过程可视化消息栏  ==========================--%>
		<jsp:include page="../common/framework/aside.jsp" />

		<%--=========================  左侧菜单  ==========================--%>
		<jsp:include page="../common/framework/lefter.jsp" />

	</div>

	<%--=========================  页面底部版权信息  ==========================--%>
	<jsp:include page="../common/framework/footer.jsp" />
	<%--=========================  选择皮肤功能  ==========================--%>
	<jsp:include page="../common/framework/page-set.jsp" />
</div>
	<div id="floating-top-right" class="floating-container"></div>
<%--===================================================--%>
<%-- END OF CONTAINER --%>

<jsp:include page="../common/framework/script.jsp" />
	<script src="${pageContext.request.contextPath}/static/js/common/bootdatatable.init.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugin/bootstrap-table/bootstrap-table.min.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugin/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugin/moment-develop/moment.min.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugin/moment-develop/local-zh-cn.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugin/daterangepicker/daterangepicker.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/static/js/common/DateFormat.js"></script>
	<script type="text/javascript">

	//时间选择框
	$('#daterangepicker').daterangepicker({
	    autoApply: true,
		showDropdowns: true,
		timePicker: true,
		timePickerIncrement: 5,
		timePicker24Hour: true,
	    //minDate:moment().subtract(15, 'days'),
	    maxDate: new Date(),
//	     minDate: moment().subtract(1, 'months'),
//	     endDate: new Date(),
	    opens: "left",
			/* dateLimit: {
			 "days": 15
			 }, */
	    alwaysShowCalendars: false,
	    ranges: {
	        "今天": [moment().format('YYYY-MM-DD 00:00'),moment().format('YYYY-MM-DD HH:mm')]
	        ,"昨天": [moment().subtract(1, 'days').format('YYYY-MM-DD 00:00'),moment().subtract(1, 'days').format('YYYY-MM-DD 23:59')]
	        ,"最近7天": [moment().subtract(7, 'days').format('YYYY-MM-DD 00:00'),moment().format('YYYY-MM-DD HH:mm')]
	        ,"最近15天": [moment().subtract(15, 'days').format('YYYY-MM-DD 00:00'),moment().format('YYYY-MM-DD HH:mm')]
	        ,"本月": [moment().format('YYYY-MM-01 HH:mm'),moment().format('YYYY-MM-DD HH:mm')]
	        //,"本季度": [moment().startOf('quarter').format('YYYY-MM-DD'),moment().endOf('quarter').format('YYYY-MM-DD')]
	    },
	    locale: {
	        format: 'YYYY-MM-DD HH:mm',
	        separator:" ~ ",
	        applyLabel: '确定',
	        cancelLabel: '取消',
	        customRangeLabel: "自定义日期",
	        daysOfWeek: ["日", "一", "二", "三", "四", "五", "六"],
	        monthNames:["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"]
	        
	    }
	},function (start, end, label) {
		console.log(label)
	    //选择时间之后操作
		startTime = start.format('YYYY-MM-DD HH:mm');
	    endTime = end.format('YYYY-MM-DD HH:mm');
	    //触发搜索
	    searchForm(startTime, endTime);
	});
$(function() {
	//加载表格
	$('#logRecord').bootdatagrid(
			"${pageContext.request.contextPath}/logRecord/queryLogRecord", {
				pagination : true,
				pageNumber : 1,
				pageSize : 10,
				dataType:'json',
				singleSelect : false,
				striped : true,
				clickToSelect : true,
	});
	//
	$('#daterangepicker').val("");
})
function invoiceFormatter(value,row,index){
	if (value) {
        return formatDateTime(value);
    }
	return value;
}
function pref_btns(value,row,index){
	var btns = '';
	btns += '<a class="btn-table-cell" onclick="tablebtnclick(this);">编辑</a>';
	btns += ' | <a class="btn-table-cell" data-toggle="tooltip" data-container="body" data-placement="top" title="日志日志">结果</a>';
	return btns;
}

function tablebtnclick(e){
	Alert.success($(e).text());
}


function getParam(startTime, endTime) {
	var beginDate;
	var endDate;
	if (startTime != null) {
		beginDate = new Date(startTime.replace(/-/g, "/"));
		endDate = new Date(endTime.replace(/-/g, "/"));
	} else {
		var dateRange = $("#daterangepicker").val();
		var dateRangePicker= dateRange.split("~");
		if (dateRangePicker.length > 1) {
			beginDate = $.trim(dateRangePicker[0]);
			endDate =$.trim(dateRangePicker[1]);
			beginDate = new Date(beginDate.replace(/-/g, "/"));
			endDate = new Date(endDate.replace(/-/g, "/"));
		}
	}
    return {
    	"execUserName": $("#execUserName").val(),
        "result": $("#result").val(),
        "operationType": $("#operationType").val(),
        "beginTime": beginDate,
        "endTime": endDate 
    };
    
};

//搜索
function searchForm(startTime, endTime){
	var params={
           silent: true,
            url:path+"/logRecord/queryLogRecord",
            query:getParam(startTime, endTime)
    };
	$('#logRecord').bootstrapTable('refresh',params);
}

//重置按钮
$("#reset").click(function () {
    $("#execUserName").val("");
    $("#result").val("");
    $("#daterangepicker").val("");
    $("#operationType").val("");
    var params={
            silent: true,
             url:path+"/logRecord/queryLogRecord",
     };
 	$('#logRecord').bootstrapTable('refresh',params);
});


function optionChange(){
	searchForm();
}

//删除按钮
function delLog() {
      var log = $('#logRecord').bootstrapTable('getSelections');
      console.log(log)
      if (log.length < 1) {
          layer.msg('请先选择你要删除的信息！', {
              icon: 7,
              time: 1000
          });
      } else {
          layer.confirm('确定要删除吗？', {icon: 3, title: '提示'}, function () {
              var logId = [];
              log.forEach(function (e) {
                  logId.push(e.logId);
              });
              $.ajax({
                  type: "post",
                  url: path+'/logRecord/deleteLogRecord',
                  data: {"logId": logId.toString()},
                  dataType: "json",
                  success: function (data) {
                      if (data == 1) {
                          layer.msg('删除成功', {
                              icon: 1,
                              time: 1000
                          });
                          searchForm();
                      } else if (data == 101) {
                          layer.msg('请登录！', {
                              icon: 7,
                              time: 1000
                          });
                      } else if (data == 303) {
                          layer.msg('对不起，您没有删除日志权限！', {
                              icon: 7,
                              time: 1000
                          });
                      } else if (data == 0) {
                          layer.msg('数据库操作失败！', {
                              icon: 2,
                              time: 1000
                          });
                      }
                  },
                  error: function (data) {
                      layer.msg('删除失败', {
                          icon: 2,
                          time: 1000
                      });
                  }
              });
          });
      }
};
</script>
</body>
</html>

